package org.seckill.enums;

/**
 * 使用枚举表示我们的常量数据字典
 * Created by Jungle on 2016/11/8.
 */
public enum SeckillStatuEnum {

    SUCCESS(1,"秒杀成功"),
    END(0,"秒杀结束"),
    REPEAT_KILL(1,"重复秒杀"),
    INNER_ERROR(2,"系统异常"),
    DATA_ERROR(3,"数据改动");

    private int state;
    private String stateInfo;

    SeckillStatuEnum(int state, String stateInfo) {
        this.state = state;
        this.stateInfo = stateInfo;
    }

    /**
     * 枚举类型判断并获取，提供一个静态的方法进行返回
     * @param state
     * @return
     */
    public static SeckillStatuEnum stateOf(int state){
        for(SeckillStatuEnum stats : values()){
            if(stats.getState() == state){
                return stats;
            }
        }
        return null;
    }

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }

    public String getStateInfo() {
        return stateInfo;
    }

    public void setStateInfo(String stateInfo) {
        this.stateInfo = stateInfo;
    }
}
